<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Application;

use Application\Model\Application;
use Application\Model\ApplicationTable;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Application\View\Helper\Menus as MenusHelper;
use Application\Model\Menu as MenuModel;


class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
        
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }
    
    
    // getAutoloaderConfig() and getConfig() methods here
    
    // Add this method:
    public function getServiceConfig()
    {
    	return array(

    			      'factories' => array(
    					'Application\Model\ApplicationTable' =>  function($sm) {
    						$tableGateway = $sm->get('ApplicationTableGateway');
    						$table = new ApplicationTable($tableGateway);
    						return $table;
    					},
    					'ApplicationTableGateway' => function ($sm) {
    						$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
    						$resultSetPrototype = new ResultSet();
    						$resultSetPrototype->setArrayObjectPrototype(new Application());
    						return new TableGateway('albumss', $dbAdapter, null, $resultSetPrototype);
    					},
    					'Application\Model\Menu' => function ($sm) {
    						$dbAdapter = $sm->get( 'Zend\Db\Adapter\Adapter' );
    						$table = new MenuModel( $dbAdapter );
    						return $table;
    					},
    					
    					
    					
    			),
    			
    			
    	);
    }
    public function getViewHelperConfig() {
    	return array (
    			'factories' => array (
    					'menu_helper' => function($sm) {
    						$helper = new MenusHelper();
    						$helper->setTable ( $sm->getServiceLocator(), 'Application\Model\Menu' );
    						return $helper;
    					}
    			)
    	);
    }
}
